import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes, Paging} from '@/api/config'

// 项目组合名称 itemGroupName
// 项目组合编码 itemGroupCode
// 检查类型 checkType
// 体检大类 inspectCategoryId categoryName
// 体检科室 deptId deptName
// 价格 price
// 排序 sort
// 初始项目组合 isFixed

// 搜索数据定义
export interface SearchFromData{
  itemGroupName?:string|null,
  itemGroupCode?:string|null,
  checkType?:string|null,
  inspectCategoryId?:string|null,
}

//表头按钮定义
export type TableOperation='add'

// 体检项目组合基本信息
export interface BaseItemGroupInfor{
  itemGroupCode:string,
  itemGroupName:string,
  checkTypeName:string,
  checkType:number,
  deptName:string,
  deptId:string,
  categoryName:string,
  inspectCategoryId:string,
  price:string,
  sort:string,
  isFixed:boolean
}
export interface ItemGroupInfor extends BaseItemGroupInfor{
  id:number
}
export type ItemGroupFormInfor = Partial<ItemGroupInfor>
export interface ItemGroupInforList {
  size:number
  total:number
  records:Array<ItemGroupInfor>
}
//获取体检项目组合列表
export const getItemGroupList = (params:SearchFromData & Paging):AxiosPromise<DataRes<ItemGroupInforList>> => {
  return request({
    url:'/api/itemGroup/page',
    method:'get',
    params
  })
}

//保存修改体检项目组合
export const saveItemGroupInfor = (data:ItemGroupFormInfor):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/itemGroup/save',
    method:'post',
    data
  })
}

// 删除体检项目组合
export const deleteItemGroup = (data:Array<number>):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/itemGroup/remove',
    method:'post',
    data
  })
}

//体检大类
interface CategoryItem {
  id:string
  categoryName:string
}

//体检大类列表
export const getCategoryList = (params):AxiosPromise<DataRes<Array<CategoryItem>>> => {
  return request({
    url:'/api/inspectCategory/checkType/category',
    method:'get',
    params
  })
}

//体检科室
interface DeptItem {
  id:string
  deptName:string
}
//体检科室列表
export const getDepartmentList = (params):AxiosPromise<DataRes<Array<DeptItem>>> => {
  return request({
    url:'/api/dept/listDeptByCheckType',
    method:'get',
    params
  })
}

//可选/已选检查项目
export interface ItemData {
  id:string
  itemCode:string //体检项目编码
  itemName:string //体检项目名称
}
//已选项目
export const getItemGroupItems = (id):AxiosPromise<DataRes<Array<ItemData>>> => {
  return request({
    url:'/api/itemGroup/get/item/' + id,
    method:'get'
  })
}
//可选项目
export const getItemGroupItemsOptional = (id):AxiosPromise<DataRes<Array<ItemData>>> => {
  return request({
    url:'/api/itemGroup/get/item/optional/' + id,
    method:'get'
  })
}

// 保存项目组合配置
export const saveItemGroupItems = (data):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/itemGroup/save/item',
    method:'post',
    data
  })
}



